package com.sun.service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.common.core.model.dto.UserExcel;
import com.sun.service.dao.UserDao;
import com.sun.service.entity.UserDo;
import com.sun.service.service.TmSysNumResourceService;
import com.sun.service.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, UserDo> implements UserService {

    @Resource
    private TmSysNumResourceService tmSysNumResourceService;

    @Override
    public boolean checkRow(UserExcel userExcel) {
        return false;
    }

    @Override
    public boolean saveAll(List<UserExcel> excelList) {
        return false;
    }

    @Override
    public void addUser(List<UserDo> userList) throws Exception {
        for (UserDo userDo : userList) {
            // 更新用户信息表
            Boolean b = tmSysNumResourceService.generateNumLock(
                    "age",
                    5,
                    (number) -> save(userDo.setAge(Long.toString(number)))
            );
            if (!b) {
                throw new Exception("流水原子性业务操作失败");
            }
        }
    }
}
